package com.yunfei.yunhetong.heTongSignManager.controller;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.yunfei.utils.log.BaseLog;
import com.yunfei.utils.string.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yunfei.common.json.object.ModelJsonUtil;;
import com.yunfei.utils.page.PageUtil;
import com.yunfei.yunhetong.heTongSignManager.service.*;
import org.springframework.web.servlet.ModelAndView;
import com.yunfei.yunhetong.heTongSignManager.bo.*;
import com.yunfei.yunhetong.heTongSignManager.entity.*;
   /**
    *@tablename hetongsignmanager
    *@author zhengyunfei
    *@createDate Thu Aug 08 09:31:33 CST 2019
    */ 
	@Controller
	@RequestMapping("/heTongSignManager")
	public class HeTongSignManagerController{
	@Autowired
	private HeTongSignManagerService heTongSignManagerService;
	/**
	*页面跳转初始化
	*@author zhengYunFei
	*@date Thu Aug 08 09:31:33 CST 2019
	*/
	@RequestMapping(value="forInit.shtml",method =  RequestMethod.GET)
	public ModelAndView forInit(){	
			ModelAndView mv=new ModelAndView("/../views/heTongSignManager");
			return mv;
		}
	/**
	*新增或者删除页面初始化
	*@author zhengYunFei
	*@date Thu Aug 08 09:31:33 CST 2019
	*/
	@RequestMapping(value = "/form.shtml",produces = "text/html;charset=UTF-8",method =  RequestMethod.POST)
	@ResponseBody
	public Object  form(String contractId){
		Object jsonStr="";
		if(!StringUtil.isNullOrEmpty(contractId)){
			HeTongSignManagerBo bo=(HeTongSignManagerBo)heTongSignManagerService.findById(contractId);
			jsonStr = ModelJsonUtil.getJsonBo(bo);
		}
		return jsonStr;
	}
	/**
	*保存或者更新信息
	*@author zhengYunFei
	*@date Thu Aug 08 09:31:33 CST 2019
	*/
	@RequestMapping(value="/save.shtml",method =  RequestMethod.POST)
	@ResponseBody
	public Map<String,Object>  save(HeTongSignManagerBo bo){
		Map<String,Object> map=new HashMap<String, Object>();
		boolean flag=false;
		String id="";
		String backInfo = null;
		try{
			if(!StringUtil.isNullOrEmpty(bo)&&!StringUtil.isNullOrEmpty(bo.getContractId())){
				heTongSignManagerService.update(bo);
				id=bo.getContractId()+"";
			}else{
				heTongSignManagerService.add(bo);
			}
			flag=true;
		}catch (Exception e) {
			e.printStackTrace();
				BaseLog.e(this.getClass(), "修改成功", e);
		}
		map.put("errorNo",0);
		map.put("message","");
		map.put("id",id);
		return map;
	}
	/**
	*删除
	*@author zhengYunFei
	*@date Thu Aug 08 09:31:33 CST 2019
	*/
	@RequestMapping(value="/delete.shtml",method =  RequestMethod.POST)
	@ResponseBody
	public Map<String,Object>  delete(String contractId){
		Map<String,Object> map=new HashMap<String, Object>();
		String backInfo = null;
		try{
			 heTongSignManagerService.delete(contractId);
		}catch (Exception e) {
			map.put("message",0);
			e.printStackTrace();
			BaseLog.e(this.getClass(), "新增成功", e);
		}
		map.put("errorNo",0);
		map.put("message","");
		return map;
	}
	/**
	*查询所有信息
	*@author zhengYunFei
	*@date Thu Aug 08 09:31:33 CST 2019
	*/
	@RequestMapping(value="/findAllList.shtml",method =  RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> findAllList(HeTongSignManagerBo bo){
	Map<String,Object> jsonMap = new HashMap<String, Object>();
		try {
			int total=0;
			total=heTongSignManagerService.count(bo);
			List<HeTongSignManagerBo> list = heTongSignManagerService.findAllList(bo);
			jsonMap.put("Rows", list);
			jsonMap.put("Total", total);
		} catch (Exception e) {
				e.printStackTrace();
			BaseLog.e(this.getClass(), "queryArticleList:查询有误", e);
		}
		return jsonMap;
	}
	/**
	*查询所有信息
	*@author zhengYunFei
	*@date Thu Aug 08 09:31:33 CST 2019
	*/
	@RequestMapping(value = "/findAllListPage.shtml",produces = "text/html;charset=UTF-8",method =  RequestMethod.POST)
	@ResponseBody
	public Object findAllListPage(HeTongSignManagerBo bo,String field, String order,String pageNum,String pageSize){
		Object jsonStr="";
		try {
				/************* 分页处理 ************/
			int skip;
			int max;
			if (StringUtil.isNullOrEmpty(pageNum))
			pageNum = "0";
			if (StringUtil.isNullOrEmpty(pageSize))
			pageSize = "20";
			skip = Integer.parseInt(pageNum);
			max = Integer.parseInt(pageSize);
			/************  分页处理结束 ***********/
			int total=0;
			bo.setCurNo((skip-1)*max+1);
			bo.setCurSize(skip*max);
			bo.setField(HeTongSignManagerBo.changeFieldColumn(field));
			bo.setOrder(order);
			String createDate=bo.getCreateDate();
			String endDate=bo.getCreateDate();
			if(!StringUtil.isNullOrEmpty(createDate)&&createDate.contains("-")){
				String dateArray[]=createDate.split(" - ");
				if(dateArray.length==2){
					createDate=dateArray[0];
					endDate=dateArray[1];
					bo.setCreateDate(createDate);
					bo.setEndDate(endDate);
				}
			}
			total=heTongSignManagerService.count(bo);
			List<HeTongSignManagerBo> list = heTongSignManagerService.findAllListPage(bo);
			jsonStr = PageUtil.getPageJson(pageNum, pageSize, max, total, list);
		} catch (Exception e) {
			e.printStackTrace();
			BaseLog.e(this.getClass(), "queryArticleList:查询有误", e);
		}
		return jsonStr;
	}
	/**
	*查询是否重复
	*@author zhengYunFei
	*@date Thu Aug 08 09:31:33 CST 2019
	*/
	@RequestMapping(value="/repeat.shtml",method =  RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> repeat(HeTongSignManagerBo bo){
		Map<String,Object> jsonMap = new HashMap<String, Object>();
		try {
			int total=0;
			total=heTongSignManagerService.count(bo);
			if(total>0){
				jsonMap.put("result",true);
			}else{
				jsonMap.put("result",false);
			}
		} catch (Exception e) {
			e.printStackTrace();
			BaseLog.e(this.getClass(), "queryArticleList:查询有误", e);
		}
		return jsonMap;
	}
}

